const path = require("path");

function getJSONToData(url) {
  const data = require(url);
  const result = path.basename(str);
  const [city, job, ss] = (result.split("-"));
  const title = `${city}-${job}-${ss.split('.')[0]}`
  const data1 = data
    .map((v) => {
      return v.salary;
    })
    .filter((v) => v.toLocaleUpperCase().includes("K"))
    .map((v) => {
      const arr = v.split("·")[0].split("K")[0].split("-");
      return arr;
    });

  const o = {};
  data1.map((v) => {
    const [start, end] = v;
    for (let i = start; i <= end; i++) {
      if (o[i]) {
        o[i]++;
      } else {
        o[i] = 1;
      }
    }
  });
  const keys = [];
  const values = [];
  Object.entries(o)
    .sort((a, b) => a[0] - b[0])
    .map((v) => {
      const [key, value] = v;
      keys.push(key);
      values.push(value);
    });
  return { keys, values, title };
}

const str = "./data/2024/12/31/北京-前端-300.json";

console.log(getJSONToData(str));
